module.exports = function($scope, $state, $stateParams, $modalInstance, $resource,$modal,toaster, item, flag){
  $scope.maxSize = 5;             //最多显示多少个按钮
  $scope.bigCurrentPage = 1;      //当前页码
  $scope.itemsPerPage = 10 ;
  $scope.typelist = [];
  $scope.objs = [];
  $scope.objs = item.indexlist;
  console.log($scope.objs);
  for (var i = 0; i < $scope.objs.length; i++){
    if ($scope.objs[i].index_img != undefined){
      $scope.objs[i].imgarr = $scope.objs[i].index_img.split(',');
    }
  }
  $scope.imgArr = [];
  $scope.image = function(index){
    var para = $state.get('app.imageupload');
    //设置上传文件夹，以自己业务命名
    angular.extend(para, {
      resolve : {  
        'dir' : function(){
          return 't1';
        }
      }  
    })
    var modalInstance = $modal.open(para);
    modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
      console.log('modal is opened');  
    });  
    modalInstance.result.then(function(result) {  
      console.log(result);  
      $scope.array = result;
      for (var i = 0; i < $scope.objs.length; i++){
        if (i == index){
          $scope.objs[i].imgarr = $scope.array;
          $scope.objs[i].index_img = $scope.array.join(',');
        }
      }
      // $scope.info.index_img = $scope.array.join(',');
    }, function(reason) {  
      console.log(reason);// 点击空白区域，总会输出backdrop  
      // click，点击取消，则会暑促cancel  
      $log.info('Modal dismissed at: ' + new Date());  
    }); 
  };
  $scope.ok = function() {
    console.log($scope.objs);
    $resource('/api/ac/goc/planAlevelApplyService/updateViewApplyCategory', {}, {}).
      save({'indexlist' : $scope.objs},  function (res) {
          if (res.errcode != 0) {
              toaster.error({title:"",body:res.errmsg});
              return;                      
          }     
          console.log(res);
          toaster.success({title:"",body:'操作成功'});     
          $modalInstance.close(); 
    });    
  }
  $scope.cancel = function(){
    $modalInstance.close(); 
  }
};